package com.yy.controller;

import com.yy.service.RedissonStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chen
 * @Date: 2022/9/23 15:06
 * @Desc: redisson 功能测试
 */
@RestController
@RequestMapping("/redisson")
public class RedissonTestController {
    @Autowired
    RedissonStockService stockService;

    @GetMapping("/stock/deduct")
    public String deduct() {
        stockService.deduct();
        return "product stock deducted";
    }

    @GetMapping("/fair/lock/{id}")
    public String fairLock(@PathVariable("id") long id) {
        stockService.fairLock(id);
        return "test fair lock";
    }

    @GetMapping("/read/lock")
    public String readLock() {
        stockService.readLock();
        return "test read lock";
    }

    @GetMapping("/write/lock")
    public String readWrite() {
        stockService.writeLock();
        return "test write lock";
    }

    @GetMapping("/semaphore/lock")
    public String semaphoreLock() {
        stockService.semaphoreLock();
        return "test semaphore lock";
    }

    @GetMapping("/latch/lock")
    public String latchLock() {
        stockService.latchLock();
        return "人到齐了,开始播放电影";
    }

    @GetMapping("/countDown/lock")
    public String countDownLock() {
        stockService.countDownLock();
        return Thread.currentThread().getName() + ": 进入了电影院";
    }
}
